package com.amat0urheu.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@Component
public class FolderCheck implements CommandLineRunner {
    //实验表存在的地方
    @Value("${file.path}")
    private String savePath;
    //CTF文件上传的的地方
    @Value("${marsctf.uploadPath}")
    private String uploadPath;
    //CTF图片
    @Value("${marsctf.imagePath}")
    private String imagePath;
    //实验图片以及各种文本编辑的图片
    @Value("${marsctf.imageUrl}")
    private String imageUrl;
    @Value("${file.path}")
    private String filePath;
    @Override
    public void run(String... args) {
        //
        List<File>fileList=new ArrayList<>();
        File experimentFile = new File(savePath);
        File ctfFile = new File(uploadPath);
        File ctfImage = new File(imagePath);
        File experimentImage = new File(imagePath+imageUrl);
        fileList.add(experimentFile);
        fileList.add(ctfFile);
        fileList.add(ctfImage);
        fileList.add(experimentImage);
        for (int i = 0; i < fileList.size(); i++) {
            if (!fileList.get(i).exists()) {
                boolean created = fileList.get(i).mkdirs();
                if (created) {
                    System.out.println("Folder created successfully.");
                } else {
                    System.out.println("Failed to create folder.");
                }
            } else {
                System.out.println("Folder already exists.");
            }
        }


    }
}
